package com.test.generics;

import test.Apple;
import test.Fruit;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class UseGeneric03 {

    public static void main(String[] args) {
        List<Fruit> fruitBasket = new ArrayList<>();
        fruitBasket.add(new Fruit());
        getOutFruits(fruitBasket);

        List<Apple> appleBasket = new ArrayList<>();
        appleBasket.add(new Apple());
        getOutFruits(appleBasket);//编译正确
    }

    /**参数使用List<? extends Fruit>**/
    public static void getOutFruits(List<? extends Fruit> basket){
        for (Fruit fruit : basket) {
            System.out.println(fruit);
            //...do something other
        }
    }
}
